﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;

using Db4objects.Db4o;
using Db4objects.Db4o.Config;
using Db4objects.Db4o.Query;
using Db4objects.Db4o.Events;

using System.Linq;
using Db4objects.Db4o.Linq;

using NLog;

using System.Text;
using System.IO;


namespace Layers.Tests
{
    [Persistent]
    public class Person
    {
        protected string _lastName;
        public string LastName { get { return _lastName; } set { _lastName = value; } }

        public Person Friend { get; set; }

        public Person(string lastName)
        {
            LastName = lastName;
        }

        public Person()
        {
        }


        [Transient]
        public int InMemoryCount;
    }

    [Persistent]
    public class Employee : Person
    {
        public double Salary { get; set; }
        public Manager Manager { get; set; }

        public Employee(string lastName) : base(lastName) { }
    }

    [Persistent]
    public class Manager : Employee, IPersistent
    {
        private IList<Person> _employees;

        public Manager(string lastName)
            : base(lastName)
        {
            _employees = Factory.NewObsList<Person>();
            Activate();
        }

        public void Activate()
        {
            _employees.WithAdd<Person>(Employees_Added)
                .WithRemove<Person>(Employees_Removed);
        }

        public IList<Person> Employees { get { return _employees; } }

        void Employees_Added(Person p)
        {
            Employee emp = p as Employee;
            if (null != emp)
                emp.Manager = this;
        }

        void Employees_Removed(Person p)
        {
            Employee emp = p as Employee;
            if (null != emp)
                emp.Manager = this;
        }
    }

}